package br.com.ufc.apsoo.hotelar.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.primefaces.model.chart.PieChartModel;

import br.com.ufc.apsoo.hotelar.dao.ServicoHospedagemDao;
import br.com.ufc.apsoo.hotelar.dao.impl.ServicoHospedagemDaoImpl;
import br.com.ufc.apsoo.hotelar.model.Servico;
import br.com.ufc.apsoo.hotelar.model.ServicoHospedagem;
import br.com.ufc.apsoo.hotelar.utils.Utils;

public class FaturamentoServicoController {
	private PieChartModel pieModel;
	private ServicoHospedagemDao servicoHospedagemDao;
	
	public FaturamentoServicoController() {
		pieModel = new PieChartModel();
		servicoHospedagemDao = new ServicoHospedagemDaoImpl();
	}
	
	public void calculaFaturamento() {
		List<ServicoHospedagem> s = servicoHospedagemDao.getServicosMaisFaturaramMesAnterior(Utils.getDataMesAnterior());
		Map<Servico, Double> mapa = new HashMap<Servico, Double>();
		for(ServicoHospedagem so : s) {
			if(mapa.containsKey(so.getServico())) {
				mapa.put(so.getServico(), mapa.get(so.getServico()) + so.getValor());
			}
			else {
				mapa.put(so.getServico(), so.getValor());
			}
		}
		for(Servico sh : mapa.keySet()) {
			pieModel.set(sh.getNome(), mapa.get(sh));
		}
	}

	public PieChartModel getPieModel() {
		return pieModel;
	}

	public void setPieModel(PieChartModel pieModel) {
		this.pieModel = pieModel;
	}
	
}
